<template>
    <div class="exempt-penalty-interest-table">
        <div class="contract-table">
            <Row>
                <Col span="24">
                    <!-- <Button type="primary" class="table-btn" @click="changeInterest" :disabled="!canChange">更改</Button> -->
                    <!-- <Button type="primary" class="table-btn" :disabled="!canSave">保存</Button> -->
                    <!-- <Button type="primary" class="table-btn" :disabled="!canSubmit">提交</Button> -->
                    <!-- <Button type="primary" class="table-btn">打印合同</Button> -->
                </Col>
                <Col span="24">
                    <Table :columns="contractTableHead" :data="contractTable.records"
                           :loading="loading" border>
                        <!-- 处理状态 -->
                        <template slot-scope="{ row }" slot="processStatus">
                            <span>{{getTitle('contractProcessStu',row.processStatus)}}</span>
                        </template>
                        <!-- 来源 -->
                        <template slot-scope="{ row }" slot="businessSource">
                            <span>{{getTitle('businessSource',row.businessSource)}}</span>
                        </template>
                        <!-- 渠道类型 -->
                        <template v-if="!isSP" slot-scope="{ row }" slot="channelType">
                            <span>{{getTitle('channelBelong',row.channelType)}}</span>
                        </template>

                        <template slot-scope="{ row }" slot="contractVersion">
                            <span>{{getTitle('contractVersion',row.contractVersion)}}</span>
                        </template>

                        <template slot-scope="{ row }" slot="action">
                            <!--
                                处理  isViewBtn ~~审核中 待补件 待补件审核~~
                                编辑 草稿
                                删除 草稿
                            -->
                            <Button :disabled="!row.isViewBtn" type="primary" size="small"
                                    @click="showContractDetial('write',row)">处理
                            </Button>
                            <Button :disabled="row.processStatus!=='approved'&&!row.isSP" type="primary" size="small"
                                    @click="printTemplate(row)">打印
                            </Button>
                            <Button :disabled="row.processStatus !== 'draft'" type="primary" size="small"
                                    @click="showContractDetial('write',row)">编辑
                            </Button>

                            <Button :disabled="row.processStatus !== 'draft'" type="error" size="small" @click="remove(row)">
                                删除
                            </Button>
                        </template>
                        <template slot="contractNo" slot-scope="{ row }">
                            <a @click="showContractDetial('read',row)">{{row.contractNo}}</a>
                        </template>
                    </Table>
                </Col>
                <Col span="24">
                    <Row type="flex" justify="end" class="table-page">
                        <Page
                            :current="contractTable.current"
                            :transfer="true"
                            :total="contractTable.total"
                            :page-size="contractTable.size"
                            @on-change="changePage"
                            @on-page-size-change="changePageSize"
                            :page-size-opts="pageSizeOpts"
                            size="small"
                            show-total
                            show-elevator
                            show-sizer
                        ></Page>
                    </Row>
                </Col>
            </Row>
        </div>
    </div>
</template>
<script>

    import {getTitleFromDataDict} from "_p/basic/assets/contract/js/utils";
    import {delById,downContractList} from "_p/basic/api/contract/contract-reissue/index";

    export default {
        name: "interestTable",
        props: {
            formValidate: {
                type: Object,
                required: true
            },
            contractTable: {
                type: Object,
                required: true
            },
            dataDict: {
                type: Object,
                required: true
            },
            // 是否是供应商
            isSP: {
                type: Boolean,
                required: true
            },
        },
        data() {
            return {
                loading: false,
                // 日期区间
                isDateErr: false,

                contractTableHead: [
                    {
                        title: "操作",
                        key: "action",
                        align: "center",
                        slot: "action",
                        width: 240,
                        fixed: 'left'
                        // fixed: "right"
                    },
                    {
                        title: "合同号",
                        key: "contractNo",
                        minWidth: 200,
                        ellipsis: true,
                        tooltip: true,
                        fixed: 'left',
                        render: (h, params) => {
                            return h('Tooltip', {
                                props: {
                                    content: params.row.contractNo,
                                    transfer: true
                                }
                            }, [h('a', {
                                class: 'contractNo',
                                style: {
                                    width: (params.column._width - 38) + 'px',
                                },
                                on: {
                                    click: () => {
                                        this.showContractDetial('read',params.row)
                                    }
                                }
                            }, params.row.contractNo)])
                        }
                    },
                    {
                        title: "申请单号",
                        key: "applyNo",
                        width: 200,
                        fixed: 'left',
                    },
                    {
                        title: "客户姓名",
                        key: "custName",
                        minWidth: 200,
                        ellipsis: true,
                        tooltip: true,
                    },
                    {
                        title: "合作商名称",
                        key: "channelFullName",
                        minWidth: 200,
                        ellipsis: true,
                        tooltip: true,
                    },
                    {
                        title: "来源",
                        key: "businesSource",
                        slot: "businessSource",
                        minWidth: 200,
                        ellipsis: true,
                        tooltip: true,
                    },
                    {
                        title: "渠道归属",
                        key: "channelType",
                        slot: "channelType",
                        minWidth: 200,
                        ellipsis: true,
                        tooltip: true,
                    },


                    {
                        title: "处理状态",
                        key: "processStatus",
                        slot: "processStatus",
                        minWidth: 200,
                        ellipsis: true,
                        tooltip: true,
                    },
                    {
                        title: "申请时间",
                        key: "applyDate",
                        ellipsis: true,
                        tooltip: true,
                        minWidth: 200,
                    },
                    {
                        title: "结束时间",
                        key: "endDate",
                        ellipsis: true,
                        tooltip: true,
                        minWidth: 200,
                    },
                ],

                pageSizeOpts: [10, 20, 50, 100],
                modal: false,
                modalTitle: "批量处理",
                canChange: false,
                canSave: false,
                canSubmit: false,
                file: null
            };
        },
        mounted() {
            this.init();
        },
        methods: {
            init() {
            },

            // 分页 Fn
            changePageSize(num) {
                this.$emit(
                    "getList",
                    Object.assign({}, this.formValidate, {pageSize: num})
                );
                this.formValidate.pageSize = num;
            },
            changePage(num) {
                this.$emit(
                    "getList",
                    Object.assign({}, this.formValidate, {pageNumber: num})
                );
                this.formValidate.pageNumber = num;
            },
            showContractDetial(type, params) {
                // console.log("showContractDetial(params)", params);

                if (!params && !params.contractNo) return;
                this.modal = false;
                params.type = type;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/contract-reissue/contract-reissue-detial/index",
                    "合同重出信息填写",
                    "ios-add",
                    params,
                    "contract-reissue-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            changeInterest() {
                this.modal = true;
            },
            closeModal() {
                this.modal = false;
            },
            getTitle(type, val) {
                let data = this.dataDict[type + "Dict"] || [];
                return getTitleFromDataDict(data, val);
            },
            // downBatchFile(v) {
            //     console.log("downBatchFile获取的参数为",v)
            //     let params = {
            //         attachmentList: v.bankCardManageVOs,
            //     }
            //     console.log(params,"调用的参数集合")
            //     let self = this
            //     downloadBatchFile(params).then(function (response) {
            //         if (response.status === 200) {
            //             self.afs.downloadFile(response);
            //             this.$Message.success("下载完成")
            //         }
            //     })
            // },
            printTemplate(params){
                let self = this;
                downContractList(params)
                    .then(function (response){
                        if (response.status === 200) {
                            self.afs.downloadFile(response);
                            this.$Message.success(res.msg);
                        }
                    })
            },
            remove(v) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除案件号 " + v.caseNo + " ?",
                    onOk: () => {
                        delById(v.id).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success(res.msg);
                                this.$emit("getList", this.formValidate);
                            }
                        });
                    }
                });
            },
        },
        computed: {}
    };
</script>
<style scoped>
    .contract-close-btns {
        padding-bottom: 28px;
        display: flex;
        flex-flow: row;
        justify-content: center;
        align-items: center;
    }

    .w160 {
        width: 160px;
    }

    .table-btn {
        margin-right: 16px;
        margin-bottom: 16px;
    }

    .applyNo {
        cursor: pointer;
    }
</style>
